import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

/// The plugin class for retrieving the Device ID.
/// For Android: returns Android ID
/// For HarmonyOS: returns ODID (Open Device ID)
class AndroidId {
  const AndroidId();

  /// The method channel used to interact with the native platform.
  static const _methodChannel = MethodChannel('android_id');

  /// Calls the native method to retrieve the Device ID.
  /// For Android: returns Android ID
  /// For HarmonyOS: returns ODID
  Future<String?> getId() async {
    // Skip web platform
    if (kIsWeb) return null;
    
    try {
      return await _methodChannel.invokeMethod<String?>('getId');
    } on PlatformException {
      // Rethrow PlatformException for specific error handling
      rethrow;
    } catch (e) {
      // If method not implemented on this platform or other errors, return null
      return null;
    }
  }
}
